﻿using NUnit.Framework;
using PowerfulExtensions.Helpers;

namespace PowerfulExtensions.Test.ByMembersEqualityComparerTest
{
    [TestFixture]
    class EqualsByMultipleParametersTest
    {
        private MyClass _obj1;
        private MyClass _obj2;

        [SetUp]
        public void Setup()
        {
            _obj1 = new MyClass();
            _obj2 = new MyClass();
        }

        [Test]
        public void When_ComparedByTwoParameters_Should_BeEqual_If_Are_TheSame()
        {
            _obj1.FloatField = 1.5f;
            _obj1.IntField = 1;
            _obj1.StrProp = "aa";

            _obj2.FloatField = 1.6f;
            _obj2.IntField = 1;
            _obj2.StrProp = "aa";

            var comparer = new ByMembersEqualityComparer<MyClass>(s => s.StrProp, s => s.IntField);
            var result = comparer.Equals(_obj1, _obj2);
            Assert.IsTrue(result);
        }

        [Test]
        public void When_ComparedByTwoParameters_Should_Not_BeEqual_If_Are_Not_TheSame()
        {
            _obj1.FloatField = 1.5f;
            _obj1.IntField = 1;
            _obj1.StrProp = "aa";

            _obj2.FloatField = 1.6f;
            _obj2.IntField = 1;
            _obj2.StrProp = "aa";

            var comparer = new ByMembersEqualityComparer<MyClass>(s => s.StrProp, s => s.FloatField);
            var result = comparer.Equals(_obj1, _obj2);
            Assert.IsFalse(result);
        }
    }
}
